/* This is a fucking comment */

#include <stdlib.h>
#include <math.h>
#include "Vector.h"

inline Vector *Vector_Create()
{
	Vector *Vector=malloc(sizeof(Vector));
	if (Vector!=NULL)
	{
		Vector->X=0.0;
		Vector->Y=0.0;
		Vector->Z=0.0;
	}
	return Vector;
}

inline void Vector_Destroy(Vector *Vector)
{
	free(Vector);
}

inline float Vector_Length(Vector *Vector)
{
	return sqrt(Vector->X*Vector->X+Vector->Y*Vector->Y+Vector->Z*Vector->Z);
}


inline void Vector_Scale(Vector *Vector, float Scale)
{
	Vector->X*=Scale;
	Vector->Y*=Scale;
	Vector->Z*=Scale;
}

inline void Vector_Normalize(Vector *Vector)
{
	float ReciprocalLength=1/Vector_Length(Vector);
	Vector->X*=ReciprocalLength;
	Vector->Y*=ReciprocalLength;
	Vector->Z*=ReciprocalLength;
}

inline float Vector_DotProduct(Vector *Vector0, Vector *Vector1)
{
	return Vector0->X*Vector1->X+Vector0->Y*Vector1->Y+Vector0->Z*Vector1->Z;
}

inline void Vector_CrossProduct(Vector *Result, Vector *Vector0, Vector *Vector1)
{
	Result->X=Vector0->Y*Vector1->Z-Vector0->Z*Vector1->Y;
	Result->Y=Vector0->Z*Vector1->X-Vector0->X*Vector1->Z;
	Result->Z=Vector0->X*Vector1->Y-Vector0->Y*Vector1->X;
}

inline void Vector_Add(Vector *Result, Vector *Vector0, Vector *Vector1)
{
	Result->X=Vector0->X+Vector1->X;
	Result->Y=Vector0->Y+Vector1->Y;
	Result->Z=Vector0->Z+Vector1->Z;
}

inline void Vector_Subtract(Vector *Result, Vector *Vector0, Vector *Vector1)
{
	Result->X=Vector0->X-Vector1->X;
	Result->Y=Vector0->Y-Vector1->Y;
	Result->Z=Vector0->Z-Vector1->Z;
}
